import Vue from "vue";
import Vuex from "vuex";
import getters from "./getters.js";

Vue.use(Vuex);


const modulesFn = require.context('./modules', true, /\.js$/);
const regex = /.*\/(.*)\.js$/
const modules = {}

modulesFn.keys().forEach(filePath => {
  let moduleName = regex.exec(filePath);
  if (moduleName !== null) {
    moduleName = moduleName[1]
  }
  const moduleObj = modulesFn(filePath)
  modules[moduleName] = {
    namespaced: true,
    ...moduleObj.default
  }
})

export default new Vuex.Store({
  modules: modules,
  getters,
});
